{% extends "base.html" %}

{% block content %}
{% import "m_mailview.html" as mview %}

{% if error is not none %}
	<p id="errormsg">{{ error }}</p>
{% endif %}

<div id="login">
	<form method="get" action="{{ phpself }}">
		<fieldset>
			<legend>Accounts</legend>
			<select name="account" id="account">
				{% for k in accounts %}
				<option value="{{ k }}"{{ k == curaccount? ' selected="selected"' : '' }}>{{ k }}</option>
				{% endfor %}
			</select>

			<button id="loadaccount">Load</button>
		</fieldset>
	</form>

	<form method="post" action="{{ phpself }}">
		<fieldset>
			<legend>Login information</legend>
			{{ mview.input('username', 'Username', config.username,
				'Your username. Often your full email address or whatever is before the @ sign in your address') }}
			{{ mview.input('password', 'Password', config.password, 'Can\'t help you with your password :-)', 'password') }}
		</fieldset>

		<fieldset>
			<legend>Options</legend>
			{{ mview.input('name', 'Your name', config.name,
				'Your name is used when sending emails so people see who the mail is from. You may leave this empty is you wish') }}
			{{ mview.input('mail', 'Your email address', config.mail,
				'Again, used when sending emails. So that people know who to reply to. May be empty, but is
				required if you want to send email (You may set it manually later)') }}
		</fieldset>

		<p>
			<a href="#" id="showadvanced">Manually adjust server parameters</a>
		</p>

		<div id="advanced" class="hideonload">
			<fieldset>
				<legend>IMAP/POP3 server</legend>
				{% if config.defaultserveronly == 1 %}
					{{ mview.input('server', 'Server', config.server, '', 'text', ' readonly="readonly" disabled="disabled"') }}
				{% else %}
					{{ mview.input('server', 'Server', config.server,
					'IMAP/POP3 server. Format: protocol://server:port') }}
				{% endif %}
				{{ mview.input('separator', 'IMAP Directory separator', config.separator,
					'Usually a dot (.), sometimes a slash (/)' ) }}
				{{ mview.input('usetls', 'Use TLS instead of SSL', config.usetls,
					'Use TLS. Enable it if the server supports it', 'checkbox') }}
				{{ mview.input('validatessl', 'Validate SSL certificate', config.validatessl,
					'Validate SSL/TLS certificate. Leave this on unles you know what it does.', 'checkbox') }}
			</fieldset>

			<fieldset>
				<legend>SMTP server</legend>

				{{ mview.input('smtpserver', 'SMTP Server', config.smtpserver,
					'SMTP server. Format: protocol://server:port') }}
				{{ mview.input('smtptls', 'Use TLS instead of SSL', config.smtptls,
					'Use TLS. Enable it if the server supports it', 'checkbox') }}
				{{ mview.input('smtpauth', 'Use SMTP authentication', config.smtpauth,
					'Use SMTP authentication', 'checkbox') }}
				{{ mview.input('smtpusername', 'Username', config.smtpusername,
					'Your SMTP username, use $username to use the same as above (This is usaully the case)') }}
				{{ mview.input('smtppassword', 'Password', config.smtppassword,
					'Your SMTP password, use $password to use the same as above (This is usually the case)', 'password') }}
			</fieldset>
		</div>

		<p>
			<label for="cookie">Save cookie/login for</label>
			<select name="cookie" id="cookie">
				<option value="0">Don't, log me out as soon as I close the browser</option>
				<option value="1">A day</option>
				<option value="7">A week</option>
				<option value="30">A month</option>
				<option value="365">A year</option>
			</select><br />

			<input type="submit" value="Login" />
		</p>
	</form>
</div>

{% endblock %}
{% block afterjs %}
<script>
	AddEvent(document.getElementById('showadvanced'), 'click', ShowAdvanced);
	AddEvent(window, 'load', LoginFormHelp);
</script>

{% endblock %}
